package com.shujia.mr.mapJoin;

import com.shujia.mr.count.MyCountDriver;
import com.shujia.mr.count.MyCountMapper;
import com.shujia.mr.count.MyCountReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;


public class MapJoinDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException, URISyntaxException {
        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf);
        job.setJarByClass(MapJoinDriver.class);
        job.setJobName("MapJoin");

        job.setMapperClass(MapJoinMapper.class);

        job.setMapOutputKeyClass(NullWritable.class);
        job.setMapOutputValueClass(Text.class);
        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(Text.class);

        // 在任务提交时，添加缓存文件
        job.addCacheFile(new URI("data/mapjoin/object.txt"));

        // addInputPath该方式读取数据是按行读取，在MapJoin中不能通过该方式进行
        FileInputFormat.addInputPath(job,new Path("data/count"));

        FileOutputFormat.setOutputPath(job,new Path("output/mapJoin"));

        job.waitForCompletion(true);

    }
}
